﻿Imports lbGlobalcom
Public Class fCaja
    Dim daSedes As dsGlobalTableAdapters.GLO_SEDESTableAdapter
    Dim daCaja As dsCajaTableAdapters.CAJ_CAJASTableAdapter

    Private Sub fCaja_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daSedes = New dsGlobalTableAdapters.GLO_SEDESTableAdapter
            daSedes.Fill(DsGlobal.GLO_SEDES)
            daCaja = New dsCajaTableAdapters.CAJ_CAJASTableAdapter
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub


    Private Sub btnCargaCajas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargaCajas.Click
        Try
            daCaja.Fill(DsCaja.CAJ_CAJAS)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub SalvaCajas(ByVal msj As Boolean)
        Try
            Me.Validate()
            CAJ_CAJASBindingSource.EndEdit()
            daCaja.Update(DsCaja.CAJ_CAJAS)
            If msj Then _
                MessageBox.Show("Se salvarón registros de caja con exito", "Salvar Caja", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub CAJ_CAJASBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CAJ_CAJASBindingNavigatorSaveItem.Click
        SalvaCajas(True)
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                CAJ_CAJASBindingSource.RemoveCurrent()
                SalvaCajas(False)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class